package drds.binlog.database_driver.packets.server;

import drds.binlog.common.Authors;
import drds.binlog.database_driver.packets.PacketWithHeaderPacket;
import drds.binlog.database_driver.utils.Bytes;
import drds.common.Author;
import lombok.Getter;
import lombok.Setter;

import java.io.IOException;

/**
 * <pre>
 * Type Of Result Packet       Hexadecimal Value Of First Byte (field_count)
 * ---------------------------------------------------------------------------
 * Result Set Packet           1-250 (first byte of Length-Coded Binary)
 * </pre>
 * <p>
 * The sequence of result set packet:
 * <p>
 * <pre>
 *   (Result Set Header Packet)  the number of columns
 *   (Field Packets)             column descriptors
 *   (EOF Packet)                marker: end of Field Packets
 *   (Row Data Packets)          row contents
 * (EOF Packet)                marker: end of Data Packets
 *
 * <pre>
 */
@Author(name = Authors.LI_YANG)
public class ResultSetHeaderPacket extends PacketWithHeaderPacket
{

    @Setter
    @Getter
    private long columnCount;
    @Setter
    @Getter
    private long extra;

    public void fromBytes(byte[] bytes) throws IOException
    {
        int index = 0;
        byte[] columnCountBytes = Bytes.readLengthBytes(bytes, index);
        columnCount = Bytes.readLength(columnCountBytes, index);
        index += columnCountBytes.length;
        if (index < bytes.length - 1)
        {
            extra = Bytes.readLength(bytes, index);
        }
    }

    public byte[] toBytes() throws IOException
    {
        return null;
    }


}
